package com.easyweb.entity;

import java.io.Serializable;
import java.util.List;

import javax.persistence.CascadeType;
import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.FetchType;
import javax.persistence.Id;
import javax.persistence.GeneratedValue;
import javax.persistence.ManyToOne;
 
import javax.persistence.OneToMany;
import javax.persistence.Table;
import javax.persistence.Version;

import org.hibernate.annotations.Cache;
import org.hibernate.annotations.CacheConcurrencyStrategy;
import org.hibernate.annotations.NamedQueries;
import org.hibernate.annotations.NamedQuery;
import org.hibernate.validator.Length;
import org.hibernate.validator.NotNull;
import org.hibernate.validator.Pattern;

@Entity
  
@NamedQueries( {					
		@NamedQuery(name = "bayilerTumKayitlar", query = "select b from Bayi b  where (b.iptal IS NULL OR  b.iptal = ' ' OR b.iptal <> '*') order by b.unvan"),
		@NamedQuery(name = "bayilerTumKayitlarIleGore", query = "select b from Bayi b  where (b.iptal IS NULL OR  b.iptal = ' ' OR b.iptal <> '*') and  b.il.id=:p1 order by b.unvan"), 
		@NamedQuery(name = "bayilerTumKayitlarKullaniciyaGore", query = "select b from Bayi b  where (b.iptal IS NULL OR  b.iptal = ' ' OR b.iptal <> '*') and  b.kullaniciKoduEski=:p1 order by b.unvan"), 
		@NamedQuery(name = "bayilerTumKayitlarIlceyeGore", query = "select b from Bayi b  where (b.iptal IS NULL OR  b.iptal = ' ' OR b.iptal <> '*') and  b.ilceEskiAdi<>' ' and b.ilceEskiAdi=:p1 order by b.unvan",cacheable=true), 
		@NamedQuery(name = "bayilerKullaniciler", query = "select  b.kullaniciKoduEski  from Bayi b  where (b.iptal IS NULL OR  b.iptal = ' ' OR b.iptal <> '*')  group by b.kullaniciKoduEski order by b.kullaniciKoduEski",cacheable=true), 
		@NamedQuery(name = "bayilerTumKayitlarSemteGore", query = "select b from Bayi b  where (b.iptal IS NULL OR  b.iptal = ' ' OR b.iptal <> '*') and  b.semtAdiEski<>' ' and  b.semtAdiEski =:p1 order by b.unvan") 
		})
		@Table
public class Bayi implements Serializable {
	private static final long serialVersionUID = -2689088175917405994L;
	@Id
	@GeneratedValue
	private Long id;

	@Column(nullable = false)
	@NotNull(message = "#{messages.errBosOlamaz}")
	private String unvan;

	@Column(nullable = false)
	@NotNull(message = "#{messages.errBosOlamaz}")
	private String ticariUnvan;

	/* adres bilgileri */
	@ManyToOne(fetch = FetchType.LAZY)
	private Iller il;

	@ManyToOne(fetch = FetchType.LAZY)
	private Ilce ilce;

	@ManyToOne(fetch = FetchType.LAZY)
	private Semtler semt;

	@Column(nullable = false, length = 50)
	@NotNull(message = "#{messages.errBosOlamaz}")
	@Length(max = 50, message = "#{messages.errUzunlukElliGecemez}")
	//@Pattern(regex = "[A-Z]?[A-Z0-9_.]+", message = "#{messages.errSadeceBuyukHarf}")
	private String cadde;

	@Column(nullable = false, length = 50)
	@NotNull(message = "#{messages.errBosOlamaz}")
	@Length(max = 50, message = "#{messages.errUzunlukElliGecemez}")
	//@Pattern(regex = "[A-Z]?[A-Z0-9_.]+", message = "#{messages.errSadeceBuyukHarf}")
	private String sokak;

	@Column(nullable = false, length = 10)
	@NotNull(message = "#{messages.errBosOlamaz}")
	@Length(max = 10, message = "#{messages.errUzunlukElliGecemez}")
	private String postaKodu;

	@Column(nullable = false, length = 10)
	@NotNull(message = "#{messages.errBosOlamaz}")
	@Length(max = 10, message = "#{messages.errUzunlukOnGecemez}")
	private String binaNo;

	@Column(nullable = false, length = 50)
	@NotNull(message = "#{messages.errBosOlamaz}")
	@Length(max = 50, message = "#{messages.errUzunlukElliGecemez}")
	//@Pattern(regex = "[A-Z]?[A-Z0-9_.]+", message = "#{messages.errSadeceBuyukHarf}")
	private String binaAdi;

	@Column(nullable = false, length = 10)
	@NotNull(message = "#{messages.errBosOlamaz}")
	@Length(max = 10, message = "#{messages.errUzunlukOnGecemez}")
	private String katNo;

	@Column(nullable = false, length = 10)
	@NotNull(message = "#{messages.errBosOlamaz}")
	@Length(max = 10, message = "#{messages.errUzunlukOnGecemez}")
	private String daireNo;

	@Column(name = "iptal", length = 1)
	private Character iptal;

	@OneToMany(fetch = FetchType.LAZY, cascade = CascadeType.ALL, mappedBy = "bayi")
	private List<BayiGps> bayiGpsler;

	@Column(nullable = true, length = 50)
	private String musteridekiKodu;
	
	@Column(nullable = true, length = 50)
	private String bayiKodu;
	
	@Column(nullable=true,length=50)
	private String ilceEskiAdi;
	
	@Column(nullable=true,length=50)
	private String semtAdiEski;

	@Column(nullable=true,length=250)
	private String adresEski;
	
	@Column(nullable=true,length=50)
	private String bayiTipiEski;
	
	@Column(nullable=true,length=50)
	private String kullaniciKoduEski;
	 	
	public Bayi() {
	}
	
  	public Bayi(Long id, String unvan, String ticariUnvan, Iller il, Ilce ilce,
			Semtler semt, String cadde, String sokak, String postaKodu,
			String binaNo, String binaAdi, String katNo, String daireNo,
			Character iptal, List<BayiGps> bayiGpsler, String musteridekiKodu,
			String bayiKodu, String ilceEskiAdi, String semtAdiEski,
			String adresEski, String bayiTipiEski, String kullaniciKoduEski) {
		super();
		this.id = id;
		this.unvan = unvan;
		this.ticariUnvan = ticariUnvan;
		this.il = il;
		this.ilce = ilce;
		this.semt = semt;
		this.cadde = cadde;
		this.sokak = sokak;
		this.postaKodu = postaKodu;
		this.binaNo = binaNo;
		this.binaAdi = binaAdi;
		this.katNo = katNo;
		this.daireNo = daireNo;
		this.iptal = iptal;
		this.bayiGpsler = bayiGpsler;
		this.musteridekiKodu = musteridekiKodu;
		this.bayiKodu = bayiKodu;
		this.ilceEskiAdi = ilceEskiAdi;
		this.semtAdiEski = semtAdiEski;
		this.adresEski = adresEski;
		this.bayiTipiEski = bayiTipiEski;
		this.kullaniciKoduEski = kullaniciKoduEski;
	}



	public String getUnvan() {
		return unvan;
	}

	public void setUnvan(String unvan) {
		this.unvan = unvan;
	}

	public String getTicariUnvan() {
		return ticariUnvan;
	}

	public void setTicariUnvan(String ticariUnvan) {
		this.ticariUnvan = ticariUnvan;
	}

	public Iller getIl() {
		return il;
	}

	public void setIl(Iller il) {
		this.il = il;
	}
	public Ilce getIlce() {
		return ilce;
	}
	public void setIlce(Ilce ilce) {
		this.ilce = ilce;
	}
	public Semtler getSemt() {
		return semt;
	}
	public void setSemt(Semtler semt) {
		this.semt = semt;
	}
	public String getCadde() {
		return cadde;
	}
	public void setCadde(String cadde) {
		this.cadde = cadde;
	}
	public String getSokak() {
		return sokak;
	}
	public void setSokak(String sokak) {
		this.sokak = sokak;
	}
	public String getPostaKodu() {
		return postaKodu;
	}
	public void setPostaKodu(String postaKodu) {
		this.postaKodu = postaKodu;
	}
	public String getBinaNo() {
		return binaNo;
	}
	public void setBinaNo(String binaNo) {
		this.binaNo = binaNo;
	}
	public String getBinaAdi() {
		return binaAdi;
	}
	public void setBinaAdi(String binaAdi) {
		this.binaAdi = binaAdi;
	}
	public String getKatNo() {
		return katNo;
	}
	public void setKatNo(String katNo) {
		this.katNo = katNo;
	}
	public String getDaireNo() {
		return daireNo;
	}
	public void setDaireNo(String daireNo) {
		this.daireNo = daireNo;
	}
	public Long getId() {
		return id;
	}
	public void setId(Long id) {
		this.id = id;
	}
	public Character getIptal() {
		return iptal;
	}
	public void setIptal(Character iptal) {
		this.iptal = iptal;
	}
	public List<BayiGps> getBayiGpsler() {
		return bayiGpsler;
	}
	public void setBayiGpsler(List<BayiGps> bayiGpsler) {
		this.bayiGpsler = bayiGpsler;
	}
	public String getMusteridekiKodu() {
		return musteridekiKodu;
	}
	public void setMusteridekiKodu(String musteridekiKodu) {
		this.musteridekiKodu = musteridekiKodu;
	}
	public String getBayiKodu() {
		return bayiKodu;
	}
	public void setBayiKodu(String bayiKodu) {
		this.bayiKodu = bayiKodu;
	}
	public String getIlceEskiAdi() {
		return ilceEskiAdi;
	}
	public String getSemtAdiEski() {
		return semtAdiEski;
	}
	public void setIlceEskiAdi(String ilceEskiAdi) {
		this.ilceEskiAdi = ilceEskiAdi;
	}
	public void setSemtAdiEski(String semtAdiEski) {
		this.semtAdiEski = semtAdiEski;
	}
	public String getAdresEski() {
		return adresEski;
	}
	public void setAdresEski(String adresEski) {
		this.adresEski = adresEski;
	}
	public String getBayiTipiEski() {
		return bayiTipiEski;
	}
	public void setBayiTipiEski(String bayiTipiEski) {
		this.bayiTipiEski = bayiTipiEski;
	}
	public String getKullaniciKoduEski() {
		return kullaniciKoduEski;
	}
	public void setKullaniciKoduEski(String kullaniciKoduEski) {
		this.kullaniciKoduEski = kullaniciKoduEski;
	}
}
